package com.qk.manangement.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qk.common.response.CustomerGetPageResponse;
import com.qk.common.response.PageResult;
import com.qk.entity.pojo.Customer;
import com.qk.manangement.service.CustomerService;
import com.qk.manangement.mapper.CustomerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer>
    implements CustomerService{

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public PageResult list(String phone, String name, Integer channel, Integer subject, Integer page, Integer pageSize) {
        // 设置默认值
        int pageNum = (page == null || page <= 0) ? 1 : page;
        int size = (pageSize == null || pageSize <= 0) ? 10 : pageSize;

        PageHelper.startPage(pageNum, size);
        try {
            List<CustomerGetPageResponse> list = customerMapper.list(phone, name, channel, subject);
            PageInfo<CustomerGetPageResponse> pageInfo = new PageInfo<>(list);
            // 构造并返回 PageResult 对象
            return new PageResult(pageInfo.getTotal(),pageInfo.getList());
        } finally {
            PageHelper.clearPage();
        }
    }

}




